<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div *ngIf="currentApi" class="api-navigation">
  <div class="api-navigation__menu">
    <gio-submenu class="api-navigation__submenu">
      <api-navigation-title
        gioSubmenuTitle
        class="api-navigation__submenu__title"
        [apiName]="currentApi.name"
        [apiVersion]="currentApi.apiVersion"
        [apiState]="currentApi.state"
        [apiLifecycleState]="currentApi.lifecycleState"
        [apiDeploymentState]="currentApi.deploymentState"
        [apiOrigin]="currentApi.originContext.origin"
      ></api-navigation-title>
      <ng-container *ngFor="let menuItem of this.subMenuItems">
        <ng-container *ngIf="!menuItem?.routerLink && menuItem?.tabs?.length > 0">
          <a [routerLink]="menuItem?.tabs[0]?.routerLink">
            <gio-submenu-item
              tabIndex="1"
              [active]="isTabActive(menuItem?.tabs)"
              [gioLicense]="menuItem?.license"
              [iconRight]="menuItem?.iconRight$ | async"
            >
              <div class="api-navigation__submenu__item">
                <mat-icon
                  *ngIf="menuItem.icon"
                  class="api-navigation__submenu__item__icon"
                  [matTooltip]="menuItem?.displayName"
                  [svgIcon]="'gio:' + menuItem.icon"
                >
                </mat-icon>
                {{ menuItem?.displayName }}
              </div>
            </gio-submenu-item>
          </a>
        </ng-container>
        <ng-container *ngIf="menuItem?.routerLink && menuItem.routerLink !== 'DISABLED'">
          <a [routerLink]="menuItem?.routerLink">
            <gio-submenu-item
              tabIndex="1"
              [active]="isActive(menuItem)"
              [gioLicense]="menuItem?.license"
              [iconRight]="menuItem?.iconRight$ | async"
            >
              <div class="api-navigation__submenu__item">
                <mat-icon
                  *ngIf="menuItem.icon"
                  class="api-navigation__submenu__item__icon"
                  [matTooltip]="menuItem?.displayName"
                  [svgIcon]="'gio:' + menuItem.icon"
                >
                </mat-icon>
                {{ menuItem?.displayName }}
              </div>
            </gio-submenu-item>
          </a>
        </ng-container>
        <api-navigation-disabled
          *ngIf="menuItem?.routerLink === 'DISABLED'"
          class="api-navigation__menu__disabled"
          [displayName]="menuItem.displayName"
          [icon]="menuItem.icon"
        ></api-navigation-disabled>
      </ng-container>
      <ng-container *ngFor="let group of this.groupItems">
        <gio-submenu-group [title]="group.title" *ngIf="group.title">
          <ng-container *ngFor="let subItem of group.items">
            <ng-container *ngIf="!subItem?.routerLink && subItem?.tabs?.length > 0">
              <a [routerLink]="subItem?.tabs[0]?.routerLink">
                <gio-submenu-item
                  tabIndex="1"
                  [active]="isTabActive(subItem?.tabs)"
                  [gioLicense]="subItem?.license"
                  [iconRight]="subItem?.iconRight$ | async"
                  >{{ subItem?.displayName }}</gio-submenu-item
                ></a
              ></ng-container
            >
            <ng-container *ngIf="subItem?.routerLink && subItem.routerLink !== 'DISABLED'">
              <a [routerLink]="subItem?.routerLink">
                <gio-submenu-item
                  tabIndex="1"
                  [active]="isActive(subItem)"
                  [gioLicense]="subItem?.license"
                  [iconRight]="subItem?.iconRight$ | async"
                  >{{ subItem?.displayName }}</gio-submenu-item
                ></a
              ></ng-container
            >
            <api-navigation-disabled
              *ngIf="subItem?.routerLink === 'DISABLED'"
              class="api-navigation__submenu__disabled"
              [displayName]="subItem.displayName"
            ></api-navigation-disabled>
          </ng-container>
        </gio-submenu-group>
      </ng-container>
    </gio-submenu>
  </div>
  <div class="api-navigation__content">
    <ng-content select="#banner"></ng-content>
    <div class="api-navigation__content__view" [ngClass]="{ breadcrumb: hasBreadcrumb, hasApiBanner: hasBanner$ | async }">
      <div class="api-navigation__content__view__banners" *ngIf="banners$ | async as banners">
        <gio-banner *ngFor="let banner of banners" [type]="banner.type">
          {{ banner.title }}
          <div *ngIf="banner.action" gioBannerAction>
            <button mat-stroked-button color="basic" (click)="banner.action.onClick(); btn.disabled = true" #btn>
              {{ banner.action.btnText }}
            </button>
          </div>
          <div gioBannerBody *ngIf="banner.body" [innerHTML]="banner.body"></div>
        </gio-banner>
      </div>

      <gio-breadcrumb *ngIf="hasBreadcrumb" class="api-navigation__breadcrumb">
        <span *gioBreadcrumbItem class="api-navigation__breadcrumb__item">APIs</span>
        <api-navigation-title
          gioSubmenuTitle
          class="api-navigation__submenu__title api-navigation__breadcrumb__item"
          [apiName]="currentApi.name"
          [apiVersion]="currentApi.apiVersion"
          [apiState]="currentApi.state"
          [apiLifecycleState]="currentApi.lifecycleState"
          [apiDeploymentState]="currentApi.deploymentState"
          [apiOrigin]="currentApi.originContext.origin"
          *gioBreadcrumbItem
        ></api-navigation-title>
        <ng-template ngFor let-item [ngForOf]="this.computeBreadcrumbItems()">
          <span *gioBreadcrumbItem class="api-navigation__breadcrumb__item">{{ item }}</span>
        </ng-template>
      </gio-breadcrumb>

      <api-navigation-header *ngIf="selectedItemHeader" [menuItemHeader]="selectedItemHeader"></api-navigation-header>

      <api-navigation-tabs
        *ngIf="selectedItemWithTabs"
        class="api-navigation__content__tabs"
        [tabMenuItems]="this.selectedItemWithTabs.tabs"
        ><router-outlet></router-outlet
      ></api-navigation-tabs>
      <ng-container *ngIf="!selectedItemWithTabs">
        <router-outlet></router-outlet>
      </ng-container>
    </div>
  </div>
</div>
